package com.zhangfb95.crosschain.infra.util;

import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * @author zhangfubing
 * @since 2023/12/22
 */
@Slf4j
public class FileUtil {

    public static String readContent(String filePath) {
        try {
            Path path;
            if (filePath.startsWith("classpath:")) {
                path = Paths.get(filePath);
            } else {
                path = Paths.get(new File(filePath).getPath());
            }
            return new String(Files.readAllBytes(path));
        } catch (Exception e) {
            log.error("Read file error: {}", e, e);
            throw new RuntimeException(e);
        }
    }
}
